
package com.idealighter.game.games.zjh.struct;

import com.idealighter.game.games.common.AbstractSeat;
import com.idealighter.game.games.common.SeatState;

import java.util.concurrent.ScheduledFuture;

import lombok.Data;
import lombok.EqualsAndHashCode;

/**
 * 炸金花seat .
 * 
 * @date 2016年6月23日 上午11:25:44
 *
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class ZjhSeat extends AbstractSeat {

  private final ZjhTable table;
  // 是否已经看过牌
  private boolean sawCard = false;
  // 是否下过暗注,下过暗注才有喜钱
  private boolean darked = false;
  // 是否已经结束(弃牌、比赛输了、超时不做操作)
  private boolean over = false;
  private boolean discard = false;
  // 下注的筹码
  private long betedchips = 0;

  // 玩家的牌数据
  private ZjhCards cards;
  // 玩家是否被控制
  private boolean control;

  // 扎金花步骤(准备、叫庄、下注、摊牌)定时Future
  public ScheduledFuture<?> stepFuture = null;

  public ZjhSeat(int order, ZjhTable table) {
    super(order);
    this.table = table;
  }

  /**
   * 重置数据.
   */
  public void reset() {
    this.totalChips = 0;
    this.sawCard = false;
    this.darked = false;
    this.over = false;
    this.discard = false;
    this.betedchips = 0;
    this.cards = null;
    this.control = false;
    this.state = SeatState.SEATED;

    if (stepFuture != null) {
      stepFuture.cancel(false);
    }
  }

  /**
   * 重置座位数据除了totalChips .
   */
  public void resetButTotalChips() {
    long totalChips = this.totalChips;
    reset();
    this.totalChips = totalChips;
  }

  /**
   * 清空座位数据 .
   */
  public void clear() {
    this.playerId = 0;
    this.playerName = null;
    reset();
  }

  @SuppressWarnings("unchecked")
  @Override
  public ZjhTable table() {
    return table;
  }
}
